############################################################## 
## MOD Title:           Patch for Weather MOD 
## MOD Author:          SwissCheese < N/A > (Daniel Schaad) http://www.RafikiTalk.com 
## MOD Description:     A: Only calls function when user is logged in. 
##                      B: Prevents remote hotlinking. 
##                      C: Fixes broken HTML on errors. 
##                      D: Adds user friendly messages for these errors: 
##                         1) no Weather City Code provided 
##                         2) wrong Code provided or weather server unavailable 
## 
## MOD Version:         1.0.0 
## 
## Installation Level:  Easy 
## Installation Time:   ~1 Minutes 
## 
## Files To Edit:       3 
##                      index.php 
##                      includes/weather.php 
##                      language/lang_english/lang_main.php 
## 
## Included Files:      (n/a) 
## 
## License:             http://opensource.org/licenses/gpl-license.php GNU Public License v2 
############################################################## 
## For security purposes, please check: http://www.phpbb.com/mods/ 
## for the latest version of this MOD. Although MODs are checked 
## before being allowed in the MODs Database there is no guarantee 
## that there are no security problems within the MOD. No support 
## will be given for MODs not found within the MODs Database which 
## can be found at http://www.phpbb.com/mods/ 
############################################################## 
## 
## Author Notes:  the Weather MOD must be installed 
##                before this patch can be applied! 
## 
## 
##         DEMO:  http://www.RafikiTalk.com 
##                (you'll need to register to see the patch in action) 
## 
## 
##        bug A:  the original MOD queried the weather server regardless 
##                of whether it was needed (user logged in) or not. 
##        fix A:  MOD now checks if user is logged in before calling the 
##                function 
## 
## 
##        bug B:  the original MOD could be called remotely by hotlinking. 
##        fix B:  added if(!defined('IN_PHPBB')){die("Hacking attempt");} 
## 
## 
##        bug C:  the original MOD breaks the HTML of the index_body.tpl when 
##                the City Code is not provided or the server is not available. 
##        fix C:  instead of parsing the remainder of the $gotWeather variable, 
##                (which eventually adds </td></tr></table> to its 'empty' self 
##                causing the HTML to break) the function returns straight to 
##                the calling point when an error occurs. 
## 
## 
##        bug D:  the original MOD returns the same Error Message regardless 
##                of whether the Weather City Code is missing or incorrect, 
##                or whether the Weather Server is unavailable. 
##        fix D:  this patch makes the MOD more user friendly by returning 
##                the following error messages (which both also provide a 
##                link to the users profile) for these two possible cases: 
## 
##       case 1:  logged in, no code provided 
##       before:  No City Selected 
##        after:  No City Selected: click here to enter a Weather City Code in your profile... 
## 
##       case 2:  logged in, wrong code provided or weather server unavailable 
##       before:  No City Selected 
##        after:  Unable To Retrieve Weather Data 
##                Either the weather server is temporarily unavailable, 
##                or the Weather City Code in your Profile is incorrect. 
## 
## 
############################################################## 
## MOD History: 
## 
##   2005-09-15 - Version 1.0.0 
##      - Initial Release 
## 
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
##############################################################   
# 
#-----[ OPEN ]------------------------------------------------ 
# 

index.php 

# 
#-----[ FIND ]------------------------------------------------ 
# 

      'MY_WEATHER' => weather($zip_code), 

# 
#-----[ REPLACE WITH ]---------------------------------------- 
# 

      'MY_WEATHER' => ($userdata['session_logged_in']) ? weather($zip_code) : '', 

# 
#-----[ OPEN ]------------------------------------------------ 
# 

includes/weather.php 

# 
#-----[ FIND ]------------------------------------------------ 
# 

function weather($weather_code) 

# 
#-----[ BEFORE, ADD ]----------------------------------------- 
# 

if ( !defined('IN_PHPBB') ) 
{ 
   die("Hacking attempt"); 
} 

# 
#-----[ FIND ]------------------------------------------------ 
# 

global $lang; 

# 
#-----[ REPLACE WITH ]---------------------------------------- 
# 

   global $lang, $phpEx; 

# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
   if ( !$weather_code ) 
   { 
      $noWeather = '<td wrap="nowrap"><br /><span class="gen">' . sprintf($lang['weather_no_city_selected'], '<a href="' . append_sid("profile.$phpEx?mode=editprofile") . '">', '</a>') . '</span><br /><br /></td>'; 
      return $noWeather; 
   } 

# 
#-----[ FIND ]------------------------------------------------ 
# 
   if ($weatherData == "") 
   { 
   $gotWeather = $lang['no_city_selected']; 
   } 

# 
#-----[ REPLACE WITH ]---------------------------------------- 
# 
   if ( !$weatherData ) 
   { 
      $noWeather = '<td align="center" wrap="nowrap"><br /><span class="gen">' . sprintf($lang['weather_not_retrieved'], '<a href="' . append_sid("profile.$phpEx?mode=editprofile") . '">', '</a>') . '</span><br /><br /></td>'; 
      return $noWeather; 
   } 

# 
#-----[ OPEN ]------------------------------------------------ 
# 

language/lang_english/lang_main.php 

# 
#-----[ FIND ]------------------------------------------------ 
# 

$lang['no_city_selected'] = 'No City Selected'; 

# 
#-----[ REPLACE WITH ]---------------------------------------- 
# 

$lang['weather_no_city_selected'] = 'No City Selected: click %s<u>here</u>%s to enter a Weather City Code in your profile...'; 

# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 

$lang['weather_not_retrieved'] = 'Unable To Retrieve Weather Data<br /><br />Either the weather server is temporarily unavailable,<br />or the Weather City Code in %s<u>your Profile</u>%s is incorrect.'; 

# 
#-----[ SAVE/CLOSE ALL FILES ]-------------------------------- 
# 
# EoM